<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Why log records are weakly ordered in a multithreaded application?</title>
<link rel="stylesheet" href="../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../index.html" title="Chapter 1. Boost.Log v2">
<link rel="up" href="../rationale.html" title="Rationale and FAQ">
<link rel="prev" href="why_weak_scoped_attributes.html" title="Why scoped attributes don't override existing attributes?">
<link rel="next" href="why_attribute_manips_dont_affect_filters.html" title="Why attributes set with stream manipulators do not participate in filtering?">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="why_weak_scoped_attributes.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../rationale.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="why_attribute_manips_dont_affect_filters.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="log.rationale.why_weak_record_ordering"></a><a class="link" href="why_weak_record_ordering.html" title="Why log records are weakly ordered in a multithreaded application?">Why log records
      are weakly ordered in a multithreaded application?</a>
</h3></div></div></div>
<p>
        Although the library guarantees that log records made in a given thread are
        always delivered to sinks in the same order as they were made in, the library
        cannot provide such guarantee for different threads. For instance, it is
        possible that thread A emits a log record and gets preempted, then thread
        B emits its log record and manages to deliver it to a sink before being preempted.
        The resulting log will contain log record from thread B before the record
        made in thread A. However, attribute values attached to the records will
        always be actual with regard to the moment of emitting the record and not
        the moment of passing the record to the sink. This is the reason for a strange,
        at first glance, situation when a log record with an earlier time stamp follows
        a record with a later time stamp. The problem appears quite rarely, usually
        when thread contention on logging is very high.
      </p>
<p>
        There are few possible ways to cope with the problem:
      </p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
            Enforce strict serialization of log record being made throughout the
            application. This solution implies a severe performance impact in multithreaded
            applications because log records that otherwise could be processed concurrently
            would have to go serial. Since this controverses one of the <a class="link" href="../../index.html#log.moti" title="Motivation">main
            library goals</a>, it was rejected.
          </li>
<li class="listitem">
            Attempt to maintain log record ordering on the sink level. This solution
            is more or less viable. On the downside, it would introduce log record
            buffering, which in turn would compromise logs reliability. In the case
            of application crash all buffered records would be lost.
          </li>
<li class="listitem">
            Bear with the problem and let mis-ordered records appear in log files
            occasionally. Order log records upon reading the files, if needed.
          </li>
</ul></div>
<p>
        The second solution was implemented as a special policy for the <a class="link" href="../detailed/sink_frontends.html#log.detailed.sink_frontends.async" title="Asynchronous sink frontend">asynchronous
        sink frontend</a>.
      </p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2007-2021 Andrey Semashev<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>).
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="why_weak_scoped_attributes.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../rationale.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="why_attribute_manips_dont_affect_filters.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
